using System;
using System.Data;
using System.Collections.Generic;
using AIM.Common;
using AIM.Model;
using BrightFrame.Aop;
namespace AIM.BLL
{
    [Connection]
	public class DepartmentBLL : ContextBoundObject
	{
		private readonly AIM.DAL.DepartmentDAL _departmentDAL = new AIM.DAL.DepartmentDAL();
        private readonly AIM.DAL.DepartmentHasArchiveTypeDAL _departmentHasArchiveTypeDAL = new DAL.DepartmentHasArchiveTypeDAL();
        private readonly AIM.DAL.SystemDAL _systemDAL = new DAL.SystemDAL();

        [TransactionMethod]
        public void Add(Department department, List<DepartmentHasArchiveType> departmentHasArchiveTypeList)
        {
            _departmentDAL.Add(department);
            department.DepartmentID = _systemDAL.GetLastInsertID();
            foreach (DepartmentHasArchiveType departmentHasArchiveType in departmentHasArchiveTypeList)
            {
                departmentHasArchiveType.Department = department;
                _departmentHasArchiveTypeDAL.Add(departmentHasArchiveType);
            }
        }

        [TransactionMethod]
        public void Update(Department department, List<DepartmentHasArchiveType> departmentHasArchiveTypeList)
        {
            _departmentDAL.Update(department);
            _departmentHasArchiveTypeDAL.DeleteByDepartmentID(department.DepartmentID);
            foreach (DepartmentHasArchiveType departmentHasArchiveType in departmentHasArchiveTypeList)
            {
                _departmentHasArchiveTypeDAL.Add(departmentHasArchiveType);
            }
        }
        [TransactionMethod]
        public void Delete(int departmentID)
        {
            _departmentHasArchiveTypeDAL.DeleteByDepartmentID(departmentID);
            _departmentDAL.Delete(departmentID);
        }

        public Department GetModel(int departmentID)
        {
            return _departmentDAL.GetModel(departmentID);
        }

        public List<Department> QueryAll()
        {
            return _departmentDAL.QueryAll();
        }

        public int CountByParentID(int parentID)
        {
            return _departmentDAL.CountByParentID(parentID);
        }
	}
}

